/**
 * 商品列表服务
 */
angular.module('goodsList.service', [])
  .factory('GoodsListFty', function ($q) {
    return {
      getGoodsListData: function (message) {
        // console.log(message);
        message = JSON.parse(message);
        console.log('店铺编号：' + message.typeNumber + '\n店铺名：' + message.name);
        var goodsListData = [
          {
            name: "全部商品",
            typeNumber: '100',
            shopNumber: message.typeNumber
          },
          {
            name: "热销",
            typeNumber: '101',
            shopNumber: message.typeNumber
          },
          {
            name: "招牌系列",
            typeNumber: '102',
            shopNumber: message.typeNumber
          },
          {
            name: "新品",
            typeNumber: '103',
            shopNumber: message.typeNumber
          }
        ];
        // 假设数据请求成功
        var deferred = $q.defer();
        deferred.resolve(goodsListData);
        this.getGoodsListDetailData(message.typeNumber, 100);
        // console.log(deferred.promise);
        return deferred.promise;
      },


      getGoodsListDetailData: function (shopNumber, typeNumber) {
        console.log('店铺：' + shopNumber + '\n分类号：' + typeNumber);

        $i = 0;
        var goodsListDetailData = [];
        var allData = [
          {
            name: '招牌肉蟹煲',
            price: '29.9',
            haoping: '666',
            buy: '600',
            shopNumber: "10101",
            productId: "1010101",
            typeNumber: '101',
            src: 'img/goodsList/1010101.jpg',
            adSrc: 'img/goodsList/10101ad.jpg'
          },
          {
            name: '鸡肉煲',
            price: '12.9',
            haoping: '666',
            buy: '600',
            shopNumber: "10101",
            productId: "1010102",
            typeNumber: '102',
            src: 'img/goodsList/1010102.jpg',
            adSrc: 'img/goodsList/10101ad.jpg'
          }, {
            name: '敬请期待',
            price: '12.9',
            haoping: '666',
            buy: '600',
            shopNumber: "10101",
            productId: "0000000",
            typeNumber: '103',
            src: 'img/goodsList/0000000.jpg',
            adSrc: 'img/goodsList/10101ad.jpg'
          },
          {
            name: '伯牙绝弦',
            price: '15.8',
            haoping: '9999+',
            buy: '9999+',
            src: 'img/goodsList/1040101.jpg',
            productId: "1040101",
            shopNumber: "10401",
            typeNumber: "101",
            adSrc: 'img/drink/10401ad.jpg'
          },
          {
            name: '寻香山茶',
            price: '20',
            haoping: '9000',
            buy: '9999+',
            productId: "1040102",
            src: 'img/goodsList/1040102.jpg',
            productId: "1040101",
            shopNumber: "10401",
            typeNumber: "101",
            adSrc: 'img/drink/10401ad.jpg'
          },
          {
            name: '桂馥兰香',
            price: '20',
            haoping: '9000',
            buy: '9999+',
            productId: "1040103",
            src: 'img/goodsList/1040103.jpg',
            productId: "1040101",
            shopNumber: "10401",
            typeNumber: "102",
            adSrc: 'img/drink/10401ad.jpg'
          },
          {
            name: '花田乌龙',
            price: '20',
            haoping: '9000',
            buy: '9999+',
            productId: "1040104",
            src: 'img/goodsList/1040104.jpg',
            productId: "1040101",
            shopNumber: "10401",
            typeNumber: "102",
            adSrc: 'img/drink/10401ad.jpg'
          },
          {
            name: '清沐观音',
            price: '20',
            haoping: '9000',
            buy: '9999+',
            productId: "1040105",
            src: 'img/goodsList/1040105.jpg',
            productId: "1040101",
            shopNumber: "10401",
            typeNumber: "103",
            adSrc: 'img/drink/10401ad.jpg'
          },
          {
            name: '白雾红尘',
            price: '20',
            haoping: '9000',
            buy: '9999+',
            productId: "1040106",
            src: 'img/goodsList/1040106.jpg',
            productId: "1040101",
            shopNumber: "10401",
            typeNumber: "103",
            adSrc: 'img/drink/10401ad.jpg'
          }
        ];
        if (shopNumber == 10101) {
          // goodsListDetailData = [
          //   {
          //     name: '招牌肉蟹煲',
          //     price: '29.9',
          //     haoping: '666',
          //     buy: '600',
          //     productId: "1010101",
          //     src: 'img/goodsList/1010101.jpg',
          //     adSrc: 'img/goodsList/10101ad.jpg'
          //   },
          //   {
          //     name: '鸡肉煲',
          //     price: '12.9',
          //     haoping: '666',
          //     buy: '600',
          //     productId: "1010102",
          //     src: 'img/goodsList/1010102.jpg'
          //   }, {
          //     name: '敬请期待',
          //     price: '12.9',
          //     haoping: '666',
          //     buy: '600',
          //     productId: "0000000",
          //     src: 'img/goodsList/0000000.jpg'
          //   }
          // ];
          // console.log(typeNumber);
          while ($i < allData.length) {
            if (allData[$i].shopNumber == shopNumber) {
              if (typeNumber == 100 || typeNumber == undefined) {
                goodsListDetailData.push(allData[$i]);
                $i++;
              } else if (allData[$i].typeNumber == typeNumber) {
                goodsListDetailData.push(allData[$i]);
                $i++;
              } else {
                // goodsListDetailData.push(allData[$i]);
                $i++;
              }
              // $i++;
            } else $i++
          }
        } else if (shopNumber == 10102) {
          goodsListDetailData = [
            {
              name: '瓦香鸡',
              price: '20',
              haoping: '666',
              buy: '600',
              productId: "1010201",
              src: 'img/goodsList/1010201.jpg',
              adSrc: 'img/goodsList/10102ad.jpg'
            }
          ];
        } else if (shopNumber == 10103) {
          goodsListDetailData = [
            {
              name: '双椒兔',
              price: '28',
              haoping: '666',
              buy: '600',
              productId: "1010301",
              src: 'img/goodsList/1010301.jpg',
              adSrc: 'img/goodsList/10103ad.jpg'
            }
          ];
        } else if (shopNumber == 10104) {
          goodsListDetailData = [
            {
              name: '鸡蛋河粉+金汤虾滑',
              price: '20',
              haoping: '666',
              buy: '600',
              productId: "1010401",
              src: 'img/goodsList/1010401.jpg',
              adSrc: 'img/goodsList/10104ad.jpg'
            }
          ];
        } else if (shopNumber == 10106) {
          goodsListDetailData = [
            {
              name: '单人超值冒菜',
              price: '18.8',
              haoping: '666',
              buy: '600',
              productId: "1010601",
              src: 'img/goodsList/1010601.jpg',
              adSrc: 'img/goodsList/10106ad.jpg'
            }, {
              name: '单人豪华冒菜',
              price: '25.9',
              haoping: '666',
              buy: '600',
              productId: "1010602",
              src: 'img/goodsList/1010602.jpg'
            }
          ];
        } else if (shopNumber == 10107) {
          goodsListDetailData = [
            {
              name: '豪华单人小火锅',
              price: '25.9',
              haoping: '666',
              buy: '600',
              productId: "1010701",
              src: 'img/goodsList/1010701.jpg',
              adSrc: 'img/goodsList/10107ad.jpg'
            }
          ];
        } else if (shopNumber == 10108) {
          goodsListDetailData = [
            {
              name: '鱼香肉丝',
              price: '16',
              haoping: '666',
              buy: '600',
              productId: "1010801",
              src: 'img/goodsList/1010801.jpg',
              adSrc: 'img/goodsList/10108ad.jpg'
            }, {
              name: '泡椒猪肝',
              price: '12',
              haoping: '666',
              buy: '600',
              productId: "1010802",
              src: 'img/goodsList/1010802.jpg'
            }
          ];
        } else if (shopNumber == 10201) {
          goodsListDetailData = [
            {
              name: '脆皮鸡腿堡+可乐',
              price: '16',
              haoping: '666',
              buy: '600',
              productId: "1020101",
              src: 'img/goodsList/1020101.jpg',
              adSrc: 'img/goodsList/10201ad.jpg'
            }
          ];
        } else if (shopNumber == 10401) {
          while ($i < allData.length) {
            if (allData[$i].shopNumber == shopNumber) {
              if (typeNumber == 100 || typeNumber == undefined) {
                goodsListDetailData.push(allData[$i]);
                // $i++;
              } else if (allData[$i].typeNumber == typeNumber) {
                goodsListDetailData.push(allData[$i]);
                // $i++;
              } else {
                // goodsListDetailData.push(allData[$i]);
                // $i++;
              }
              $i++;
            } else $i++
          }
        } else if (shopNumber == 10402) {
          goodsListDetailData = [
            {
              name: '薄荷奶绿',
              price: '9',
              haoping: '999',
              buy: '999',
              productId: "1040201",
              src: 'img/goodsList/1040201.jpg',
              adSrc: 'img/drink/10402ad.jpg'
            }
          ];
        } else if (shopNumber == 10403) {
          goodsListDetailData = [
            {
              name: '冷翠茶',
              price: '6',
              haoping: '666',
              buy: '600',
              productId: "1040301",
              src: 'img/goodsList/1040301.jpg',
              adSrc: 'img/drink/10403ad.jpg'
            }
          ];
        } else if (shopNumber == 10404) {
          goodsListDetailData = [
            {
              name: '招牌汤圆奶茶',
              price: '14',
              haoping: '666',
              buy: '600',
              productId: "1040401",
              src: 'img/goodsList/1040401.jpg',
              adSrc: 'img/drink/10404ad.jpg'
            }
          ];
        } else if (shopNumber == 10405) {
          goodsListDetailData = [
            {
              name: '茉莉奶绿',
              price: '14',
              haoping: '666',
              buy: '600',
              productId: "1040501",
              src: 'img/goodsList/1040501.jpg',
              adSrc: 'img/drink/10405ad.jpg'
            }
          ];
        } else if (shopNumber == 10406) {
          goodsListDetailData = [
            {
              name: '超A芝士桃桃',
              price: '20',
              haoping: '666',
              buy: '600',
              productId: "1040601",
              src: 'img/goodsList/1040601.jpg',
              adSrc: 'img/drink/10406ad.jpg'
            }
          ];
        } else if (shopNumber == 10407) {
          goodsListDetailData = [
            {
              name: '蓝朋友椰椰拿铁',
              price: '14',
              haoping: '666',
              buy: '600',
              productId: "1040701",
              src: 'img/goodsList/1040701.jpg',
              adSrc: 'img/drink/10407ad.jpg'
            }
          ];
        } else {
          goodsListDetailData = [
            {
              name: '敬请期待',
              price: '12.9',
              haoping: '666',
              buy: '600',
              productId: "0000000",
              src: 'img/goodsList/0000000.jpg',
              adSrc: 'img/drink/null.jpg'
            }
          ];
        }
        // }
        // 假设数据请求成功
        var deferred = $q.defer();
        // console.log(goodsListDetailData);
        deferred.resolve(goodsListDetailData);
        return deferred.promise;
      },

      //2.下拉加载更多列表商品
      loadMoreGoodsList: function (shopNumber) {
        var goodsListDetailData = [];
        // console.log('店铺：' + shopNumber);
        if (shopNumber == 10101) {
          goodsListDetailData = [
            {
              name: '招牌肉蟹煲',
              price: '29.9',
              haoping: '666',
              buy: '600',
              productId: "1010101",
              src: 'img/goodsList/1010101.jpg',
              adSrc: 'img/goodsList/10101ad.jpg'
            },
            {
              name: '鸡肉煲',
              price: '12.9',
              haoping: '666',
              buy: '600',
              productId: "1010102",
              src: 'img/goodsList/1010102.jpg',
              adSrc: 'img/goodsList/10101ad.jpg'
            }, {
              name: '敬请期待',
              price: '12.9',
              haoping: '666',
              buy: '600',
              productId: "0000000",
              src: 'img/goodsList/0000000.jpg',
              adSrc: 'img/goodsList/10101ad.jpg'
            }
          ];
          // console.log(goodsListDetailData);
        } else if (shopNumber == 10102) {
          goodsListDetailData = [
            {
              name: '瓦香鸡',
              price: '20',
              haoping: '666',
              buy: '600',
              productId: "1010201",
              src: 'img/goodsList/1010201.jpg',
              adSrc: 'img/goodsList/10102ad.jpg'
            }
          ];
        } else if (shopNumber == 10103) {
          goodsListDetailData = [
            {
              name: '双椒兔',
              price: '28',
              haoping: '666',
              buy: '600',
              productId: "1010301",
              src: 'img/goodsList/1010301.jpg',
              adSrc: 'img/goodsList/10103ad.jpg'
            }
          ];
        } else if (shopNumber == 10104) {
          goodsListDetailData = [
            {
              name: '鸡蛋河粉+金汤虾滑',
              price: '20',
              haoping: '666',
              buy: '600',
              productId: "1010401",
              src: 'img/goodsList/1010401.jpg',
              adSrc: 'img/goodsList/10104ad.jpg'
            }
          ];
        } else if (shopNumber == 10106) {
          goodsListDetailData = [
            {
              name: '单人超值冒菜',
              price: '18.8',
              haoping: '666',
              buy: '600',
              productId: "1010601",
              src: 'img/goodsList/1010601.jpg',
              adSrc: 'img/goodsList/10106ad.jpg'
            }, {
              name: '单人豪华冒菜',
              price: '25.9',
              haoping: '666',
              buy: '600',
              productId: "1010602",
              src: 'img/goodsList/1010602.jpg'
            }
          ];
        } else if (shopNumber == 10107) {
          goodsListDetailData = [
            {
              name: '豪华单人小火锅',
              price: '25.9',
              haoping: '666',
              buy: '600',
              productId: "1010701",
              src: 'img/goodsList/1010701.jpg',
              adSrc: 'img/goodsList/10107ad.jpg'
            }
          ];
        } else if (shopNumber == 10108) {
          goodsListDetailData = [
            {
              name: '鱼香肉丝',
              price: '16',
              haoping: '666',
              buy: '600',
              productId: "1010801",
              src: 'img/goodsList/1010801.jpg',
              adSrc: 'img/goodsList/10108ad.jpg'
            }, {
              name: '泡椒猪肝',
              price: '12',
              haoping: '666',
              buy: '600',
              productId: "1010802",
              src: 'img/goodsList/1010802.jpg'
            }
          ];
        } else if (shopNumber == 10201) {
          goodsListDetailData = [
            {
              name: '脆皮鸡腿堡+可乐',
              price: '16',
              haoping: '666',
              buy: '600',
              productId: "1020101",
              src: 'img/goodsList/1020101.jpg',
              adSrc: 'img/goodsList/10201ad.jpg'
            }
          ];
        } else if (shopNumber == 10401) {
          goodsListDetailData = [
            {
              name: '伯牙绝弦',
              price: '15.8',
              haoping: '9999+',
              buy: '9999+',
              productId: "1040101",
              src: 'img/goodsList/1040101.jpg',
              adSrc: 'img/drink/10401ad.jpg'
            },
            {
              name: '寻香山茶',
              price: '20',
              haoping: '9000',
              buy: '9999+',
              productId: "1040102",
              src: 'img/goodsList/1040102.jpg'
            },
            {
              name: '桂馥兰香',
              price: '20',
              haoping: '9000',
              buy: '9999+',
              productId: "1040103",
              src: 'img/goodsList/1040103.jpg'
            },
            {
              name: '花田乌龙',
              price: '20',
              haoping: '9000',
              buy: '9999+',
              productId: "1040104",
              src: 'img/goodsList/1040104.jpg'
            },
            {
              name: '清沐观音',
              price: '20',
              haoping: '9000',
              buy: '9999+',
              productId: "1040105",
              src: 'img/goodsList/1040105.jpg'
            },
            {
              name: '白雾红尘',
              price: '20',
              haoping: '9000',
              buy: '9999+',
              productId: "1040106",
              src: 'img/goodsList/1040106.jpg'
            }
          ];
        } else if (shopNumber == 10402) {
          goodsListDetailData = [
            {
              name: '薄荷奶绿',
              price: '9',
              haoping: '999',
              buy: '999',
              productId: "1040201",
              src: 'img/goodsList/1040201.jpg',
              adSrc: 'img/drink/10402ad.jpg'
            }
          ];
        } else if (shopNumber == 10403) {
          goodsListDetailData = [
            {
              name: '冷翠茶',
              price: '6',
              haoping: '666',
              buy: '600',
              productId: "1040301",
              src: 'img/goodsList/1040301.jpg',
              adSrc: 'img/drink/10403ad.jpg'
            }
          ];
        } else if (shopNumber == 10404) {
          goodsListDetailData = [
            {
              name: '招牌汤圆奶茶',
              price: '14',
              haoping: '666',
              buy: '600',
              productId: "1040401",
              src: 'img/goodsList/1040401.jpg',
              adSrc: 'img/drink/10404ad.jpg'
            }
          ];
        } else if (shopNumber == 10405) {
          goodsListDetailData = [
            {
              name: '茉莉奶绿',
              price: '14',
              haoping: '666',
              buy: '600',
              productId: "1040501",
              src: 'img/goodsList/1040501.jpg',
              adSrc: 'img/drink/10405ad.jpg'
            }
          ];
        } else if (shopNumber == 10406) {
          goodsListDetailData = [
            {
              name: '超A芝士桃桃',
              price: '20',
              haoping: '666',
              buy: '600',
              productId: "1040601",
              src: 'img/goodsList/1040601.jpg',
              adSrc: 'img/drink/10406ad.jpg'
            }
          ];
        } else if (shopNumber == 10407) {
          goodsListDetailData = [
            {
              name: '蓝朋友椰椰拿铁',
              price: '14',
              haoping: '666',
              buy: '600',
              productId: "1040701",
              src: 'img/goodsList/1040701.jpg',
              adSrc: 'img/drink/10407ad.jpg'
            }
          ];
        } else {
          goodsListDetailData = [
            {
              name: '敬请期待',
              price: '12.9',
              haoping: '666',
              buy: '600',
              productId: "0000000",
              src: 'img/goodsList/0000000.jpg',
              adSrc: 'img/drink/null.jpg'
            }
          ];
        }
        // }
        // 假设数据请求成功
        var deferred = $q.defer();
        // console.log(goodsListDetailData);
        deferred.resolve(goodsListDetailData);
        return deferred.promise;
      }
    }
  });
